package com.hdax.dm.mapstructs;

import com.hdax.common.dto.HotItemDto;
import com.hdax.common.dto.IndexNavDto;
import com.hdax.dm.entity.item.DmItemType;
import com.hdax.dm.service.DmItemService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


//自动加一个spring注解，Controller
@Mapper(componentModel = "spring")
public abstract  class IndexNavDtoMapper {

    @Autowired
    private DmItemService dmItemService;


    @Mappings({
        @Mapping(source = "children",target = "children"),
        @Mapping(target = "hotItems",expression = "java(getHotItems(sources.getId()))")
    })
    public abstract IndexNavDto toTarger(DmItemType sources);

    public abstract List<IndexNavDto> toTargetList(List<DmItemType> sources);

    protected List<HotItemDto> getHotItems(Long itemType1Id){
       return  dmItemService.hotItems(itemType1Id);

    }

}
